#ifndef MAZ_FIFF_WAV_H_
#define MAZ_FIFF_WAV_H_

#define RIFF_WAV_SAMPLERATE_8K          8000
#define RIFF_WAV_SAMPLERATE_16K         16000
#define RIFF_WAV_SAMPLERATE_44K1        44100
#define RIFF_WAV_SAMPLERATE_STR(x)      (x == RIFF_WAV_SAMPLERATE_8K)   ? "8KHz"    : \
                                        (x == RIFF_WAV_SAMPLERATE_16K)  ? "16KHz"   : \
                                        (x == RIFF_WAV_SAMPLERATE_44K1) ? "44.1KHz" : "UNKONW"

#define RIFF_WAV_BITDEPTH_8BIT          8
#define RIFF_WAV_BITDEPTH_16BIT         16
#define RIFF_WAV_BITDEPTH_STR(x)       (x == RIFF_WAV_BITDEPTH_8BIT)   ? "8Bit"    : \
                                        (x == RIFF_WAV_BITDEPTH_16BIT)  ? "16Bit"   : "UNKONW"

#define RIFF_WAV_CHANNEL_MONO           1
#define RIFF_WAV_CHANNEL_STEREO         2
#define RIFF_WAV_CHANNEL_STR(x)         (x == RIFF_WAV_CHANNEL_MONO)    ? "MONO"    : \
                                        (x == RIFF_WAV_CHANNEL_STEREO)  ? "STEREO"  : "UNKONW"

#define RIFF_WAV_FORMAT_PCM             1
#define RIFF_WAV_FORMAT_G711A           6
#define RIFF_WAV_FORMAT_G711U           7
#define RIFF_WAV_FORMAT_STR(x)          (x == RIFF_WAV_FORMAT_PCM)      ? "PCM"     : \
                                        (x == RIFF_WAV_FORMAT_G711A)    ? "G711A"   : \
                                        (x == RIFF_WAV_FORMAT_G711U)    ? "G711U"   : "UNKONW"

typedef struct {
    char        id[4];
    uint32_t    size;
    uint16_t    format;
    uint16_t    channel;
    uint32_t    samplerate;
    uint32_t    byterate;
    uint16_t    blockalign;
    uint16_t    bitdepth;
} WAVE_FMT;

typedef struct {
    char        id[4];
    uint32_t    size;
} WAVE_DATA;

typedef struct {
    char        id[4];
    uint32_t    size;
    char        fmt[4];
    WAVE_FMT    subchunk1;
    WAVE_DATA   subchunk2;
} WAVE_HEADER;

typedef struct {
    int         samplerate;         // RIFF_WAV_SAMPLERATE_8K
    int         bitdepth;           // RIFF_WAV_BITDEPTH_8BIT
    int         channel;            // RIFF_WAV_CHANNEL_MONO
    int         format;             // RIFF_WAV_FORMAT_PCM
    int         length;
} WAVE_INFO;


int riff_wav_header_pack(WAVE_INFO *info, WAVE_HEADER *header);

#endif /* MAZ_FIFF_WAV_H_ */
